package com.xiemulei.gulimall.search.web;

import com.xiemulei.gulimall.search.service.MallSearchService;
import com.xiemulei.gulimall.search.vo.SearchParam;
import com.xiemulei.gulimall.search.vo.SearchResult;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import jakarta.annotation.Resource;

@Controller
public class SearchController {
    @Resource
    MallSearchService mallSearchService;

    @GetMapping("/list.html")
    public String search(SearchParam param, Model model, HttpServletRequest request) {
        String queryString = request.getQueryString();
        param.set_queryString(queryString);
        // 根据查询参数，去 es 中检索商品
        SearchResult result = mallSearchService.search(param);
        model.addAttribute("result", result);
        return "list";
    }
}
